<template>
  <div :class="className" :style="{width: width, height: height}" />
</template>
<script>
import * as echarts from 'echarts'
import('echarts/theme/macarons')
const animationDuration = 3000
export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOption()
    },
    setOption() {
      this.chart.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
          boundaryGap: true,
          axisTick: {
            alignWithLabel: true
          }
        },
        yAxis: {
          show: true,
          type: 'value',
          axisLine: {
            show: true
          }
        },
        grid: {
          containLabel: true,
          left: 5,
          bottom: 15,
          top: 10,
          right: 10
        },
        series: [
          {
            name: 'PageA',
            type: 'bar',
            data: [30, 52, 200, 334, 1390, 330, 220],
            stack: 'visitors',
            barWidth: '50%',
            animationDuration
          },
          {
            name: 'PageB',
            type: 'bar',
            data: [80, 52, 200, 334, 390, 330, 220],
            stack: 'visitors',
            barWidth: '50%',
            animationDuration
          },
          {
            name: 'PageC',
            type: 'bar',
            data: [30, 52, 200, 334, 390, 330, 220],
            stack: 'visitors',
            barWidth: '50%',
            animationDuration
          }
        ]
      })
    }
  }
}
</script>
